<template>
  <div>
    {{$store.state.name}}
    <button @click="changeName">改名字</button>
  </div>
</template>

<script>
import { useStore } from 'vuex'
export default {
  name: 'App',
  setup () {
    // 生成store实例
    const store = useStore()
    const name = store.state.name
    // function changeName () {
    //   alert('11')
    //   store.commit('setname')
    // }
    const changeName = () => {
      store.dispatch('updatename')
    }
    return { name, changeName }
  }
}
</script>

<style lang="less">
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
}

#nav {
  padding: 30px;

  a {
    font-weight: bold;
    color: #2c3e50;

    &.router-link-exact-active {
      color: #42b983;
    }
  }
}
</style>
